#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// This test checks gainCard().

int main()
{
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	struct gameState G;
	int randomSeed;
	int r, m;
	int numPlayer = 2;
	
	srand(time(NULL));
	randomSeed = (rand() % 10)+1;
	
	// try to gain a curse that is out of supply
	m = initializeGame(numPlayer, k, randomSeed, &G);
	G.supplyCount[curse] = 0;
	r = gainCard(0, &G, 2, 0);
	printf("Attempting to gain a card out of supply. ");
	if(r == -1)
		printf("Unable to take card. Test PASSED.\n");
	else
		printf("Able to take card. Test FAILED.\n");
		
	// try to gain a remodel card, which is not in this particular game
	r = gainCard(12, &G, 2, 0);
	printf("Attempting to gain an invalid card. ");
	if(r == -1)
		printf("Unable to take card. PASSED.\n");
	else
		printf("Able to take card. FAILED.\n");

	// add a curse card to deck
	G.supplyCount[curse] = 200;
	G.deckCount[0] = 50;
	r = gainCard(0, &G, 1, 0);
	printf("Attempting to add card to deck. ");
	if(G.deckCount[0] == 51)
		printf("Deck incremented. PASSED.\n");
	else
		printf("Deck not incremented. FAILED.\n");
	printf("Checking if supply was decremented. ");
	if(G.supplyCount[0] == 199)
		printf("Supply decremented. PASSED.\n");
	else
		printf("Supply not decremented. FAILED.\n");
		
	// add a copper card to hand
	G.handCount[0] = 0;
	G.supplyCount[1] = 200;
	r = gainCard(1, &G, 2, 0);
	printf("Attempting to add card to hand. ");
	if(G.handCount[0] == 1)
		printf("Card added. PASSED.\n");
	else
		printf("Card not added. FAILED.\n");
	if(G.hand[0][0] != 1)
		printf("But wrong card added to hand. FAILED!\n");
	else
		printf("Correct card added to hand. PASSED.\n");
	printf("Checking if supply was decremented. ");
	if(G.supplyCount[1] == 199)
		printf("Supply decremented. PASSED.\n");
	else
		printf("Supply not decremented. FAILED.\n");
	
	// add to discard
	G.discardCount[0] = 0;
	G.supplyCount[1] = 1;
	r = gainCard(1, &G, 0, 0);
	printf("Discarding card. ");
	if(G.discard[0][0] == 1 && G.discardCount[0] == 1)
		printf("Card discarded. PASSED.\n");
	else
		printf("Card not added to discard. FAILED.\n");
	printf("Was supply decremented? ");
	if(G.supplyCount[1] == 0)
		printf("Yes. PASSED.\n");
	else
		printf("No. FAILED.\n");
	
		
	return 0;
}